package com.shallwead.bna.Async;

import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;

import com.shallwead.bna.BnA;
import com.shallwead.bna.util.JSON;

public class GetFrontAdAsync extends AsyncTask<String, String, Boolean> {

	Context mContext;

	public GetFrontAdAsync(Context mContext) {
		this.mContext = mContext;
	}

	@Override
	protected Boolean doInBackground(String... params) {
		try {
			BnA.adFront = JSON.getFrontAd();
			BnA.adBackList = JSON.getBackAdList();
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	protected void onPostExecute(Boolean result) {
		super.onPostExecute(result);
		if (result && BnA.adFront != null) {
			BnA.showFrontAd(mContext, BnA.adFront);
		}
		new GetBackAdAsync().execute();
	}

	class GetBackAdAsync extends AsyncTask<String, String, Boolean> {

		@Override
		protected Boolean doInBackground(String... params) {
			try {
				BnA.adBackList = JSON.getBackAdList();
				return true;
			} catch (Exception e) {
				return false;
			}
		}

	}

}
